package com.ruoyi.logistic.controller;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.logistic.domain.NetworkSettleSubject;
import com.ruoyi.logistic.service.NetworkSettleSubjectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/network_settleSubject")
@Api(tags = "网点财务_结算科目")
public class NetworkSettleSubjectController {
    @Autowired
    private NetworkSettleSubjectService networkSettleSubjectService;
    @ApiOperation("显示结算科目列表")
    @GetMapping("/selectAll")
    public R selectAll(){
        List<NetworkSettleSubject> networkSettleSubjects = networkSettleSubjectService.selectAll();
        if (networkSettleSubjects == null || networkSettleSubjects.size() == 0){
            return R.fail("暂无数据");
        }else {
            return R.ok(networkSettleSubjects);
        }
    }
    @ApiOperation("添加结算科目")
    @PostMapping("/insert")
    @ResponseBody
    public R insert(NetworkSettleSubject networkSettleSubject){
        Boolean isAdd = networkSettleSubjectService.insert(networkSettleSubject);
        if (isAdd){
            return R.ok("添加成功");
        }else {
            return R.fail("添加失败");
        }
    }
    @ApiOperation("修改结算科目")
    @PostMapping("/update")
    @ResponseBody
    public R update(NetworkSettleSubject networkSettleSubject){
        Boolean isUpdate = networkSettleSubjectService.update(networkSettleSubject);
        if (isUpdate){
            return R.ok("修改成功");
        }else {
            return R.fail("修改失败");
        }
    }
    @ApiOperation("删除结算科目")
    @PostMapping("/deleteById")
    public R deleteById(Integer id){
        Boolean isDelete = networkSettleSubjectService.deleteById(id);
        if (isDelete){
            return R.ok("删除成功");
        }else {
            return R.fail("删除失败");
        }
    }
}
